//
//  MessageCenterStore.m
//  NewPro
//
//  Created by RYX on 2018/10/29.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "MessageCenterStore.h"
#import "MessageCenterModel.h"

@implementation MessageCenterStore

#pragma mark - 获取消息
- (void)getMessageInfoWithCustomId:(NSString *)customId andType:(NSString *)type andIsRead:(BOOL)isRead Success:(void(^)(NSArray *arr, BOOL isRead))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/notifyRecord/getMessageList",IP];
    
    NSDictionary *dic = @{
                          @"customId":customId,
                          @"type":type
                          };
    
    NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    if (isRead) {
        
        [pars setObject:@"1" forKey:@"isRead"];
    }
    
    [HttpTool postUrlWithString:url parameters:pars success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSArray *listArr = [MessageCenterModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"items"]];
            
            BOOL isRead = NO;
            
            for (MessageCenterModel *model in listArr) {
                
                if ([model.isRead isEqualToString:@"0"]) {
                    
                    isRead = YES;
                    break;
                }
            }
            
            success(listArr, isRead);
            
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
       
        failure(error);
    }];
    
}

@end
